import Formatter from './cleave_formatter'
let timer = null
export default {
  inserted (el, bindding, vnode) {
    const input = el.querySelector('input')
    input.value = new Formatter().format(input.value)
    input.dispatchEvent(new Event('input'))
  },
  update (el, bindding, vnode) {
    if (timer) window.clearTimeout(timer)
    timer = setTimeout(() => {
      const input = el.querySelector('input')
      input.value = new Formatter().format(input.value)
      input.dispatchEvent(new Event('input'))
    }, 10)
  },
  unbind (el, bindding, vnode) {}
}
